package com.aat.dxfy.thread;

public class TO {
	private static boolean flag;

	public static void main(String[] args) throws Exception {
		// 1，单对象多线程；

		// 2,多对象多线程；
		test02();
		
		// 3,多对象单线程；

		// --------------------------

	}

	public static void test01() throws Exception {
		// 1，单对象多线程；
		ExcuteThread simpleOBJ = new ExcuteThread();
		new Thread(simpleOBJ).start();
		new Thread(simpleOBJ).start();
		Thread.sleep(1000);
		flag = true;
		System.out.println(flag);
	}
	
	public static void test02() throws Exception {
		// 2,多对象多线程；
		ExcuteThread simpleOBJ1 = new ExcuteThread();
		ExcuteThread simpleOBJ2 = new ExcuteThread();
		
		
		new Thread(simpleOBJ1).start();
		new Thread(simpleOBJ2).start();
		
		
		Thread.sleep(1000);
		flag = true;
		System.out.println(flag);
	}
	
	public static void test03() throws Exception {
		// 3,多对象单线程；
		ExcuteThread simpleOBJ1 = new ExcuteThread();
		final ExcuteThread simpleOBJ2 = new ExcuteThread();
		Thread t = new Thread(simpleOBJ1){
			@Override
			public void run() {
				simpleOBJ2.run();
			}
		};
		t.start();
		
		Thread.sleep(1000);
		flag = true;
		System.out.println(flag);
	}

	private static class ExcuteThread implements Runnable {
		
		@Override
		public void run() {
			while (!flag) {
				System.out.println(Thread.currentThread().getName());
			}
		}
	}
}
